//
//  HomeCheckBar.m
//  Ginix
//
//  Created by fzq on 2025/2/24.
//

#import "HomeCheckBar.h"

@interface HomeCheckBar()
@property (nonatomic,strong) UILabel * infoLabel;
@property (nonatomic,strong) UILabel * numLabel;
@end

@implementation HomeCheckBar

-(instancetype)initWithFrame:(CGRect)frame{
    
    if(self = [super initWithFrame:frame]){
        [self setSubViewLayout];
    }
    return self;
}
-(void)setSubViewLayout{
    
    [self setCornerRadius:20 * FMScaleX];
    self.backgroundColor = RDRGB(0xE9E5E1);
    
    [self addSubview:self.infoLabel];
    [self addSubview:self.numLabel];
    [_numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.infoLabel.mas_right).offset(-7 * FMScaleX);
        make.top.equalTo(self.infoLabel.mas_top).offset(2* FMScaleX);
        make.height.mas_offset(22 * FMScaleX);
    }];
}

-(void)setProgress:(CGFloat )progress{
    
    self.numLabel.text = [NSString stringWithFormat:@"%.0f%%",progress];
    
   CGFloat width = (self.getWidth - 16 * FMScaleX - 33 * FMScaleX) / 100 ;
    
    self.infoLabel.frame = CGRectMake(8 * FMScaleX, 7 * FMScaleX, 33 * FMScaleX + width * progress, 26 * FMScaleX);
    [self.infoLabel removeGradientLayer];
    [self.infoLabel gradientLayer:@[(__bridge id)RDRGBA(0x9A7242, 0.39).CGColor,(__bridge id)RDRGB(0x9A7242).CGColor]];

}


-(UILabel *)infoLabel{
    
    if(!_infoLabel){
        _infoLabel = [[UILabel alloc]initWithFrame:CGRectMake(8 * FMScaleX, 7 * FMScaleX, 33 * FMScaleX, 26 * FMScaleX)];
        [_infoLabel setCornerRadius:13 * FMScaleX];
        [_infoLabel gradientLayer:@[(__bridge id)RDRGBA(0x9A7242, 0.39).CGColor,(__bridge id)RDRGB(0x9A7242).CGColor]];
    }
    return _infoLabel;
}
-(UILabel *)numLabel{
    
    if(!_numLabel){
        _numLabel = [[UILabel alloc]init];
        _numLabel.font = Medium(13);
        _numLabel.textColor = UIColor.whiteColor;
        _numLabel.text = @"0%";
    }
    return _numLabel;
}
@end
